package DayFour;

import java.util.Scanner;

/*给定一个十进制数M，以及需要转换的进制数N。将十进制数M转化为N进制数
        输入描述：
        输入为一行，M(32位整数)、N(2 ≤ N ≤ 16)，以空格隔开。
        输出描述：
        为每个测试实例输出转换后的数，每个输出占一行。如果N大于9，则对应的数字规则参考16进制（比如，10
        用A表示，等等）
        示例1:
        输入
        7 2
        输出
        NOWCODER.COM
        牛客网·互联网名企笔试/面试题库
        牛客出品-http://www.nowcoder.com
        111*/
public class TestTwo {
    public static int shiftTwo(int x){
        StringBuilder builder = new StringBuilder();
        int outCome = 0;
        while(x>0){
            builder.append(x%2);
            x/=2;
        }
        builder.reverse();
        outCome = Integer.valueOf(String.valueOf(builder));
        return outCome;
    }

    public static int shiftEight(int x){
        StringBuilder builder = new StringBuilder();
        int outCome = 0;
        while(x>0){
            builder.append(x%8);
            x/=8;
        }
        builder.reverse();
        outCome = Integer.valueOf(String.valueOf(builder));
        return outCome;
    }
    public static StringBuilder shiftSixTeen(int x){
        StringBuilder builder = new StringBuilder();
        while(x>0){
            switch (x%16){
                case 10:builder.append("A");break;
                case 11:builder.append("B");break;
                case 12:builder.append("C");break;
                case 13:builder.append("D");break;
                case 14:builder.append("E");break;
                case 15:builder.append("F");break;
                default:builder.append(x%16);break;
            }
            x/=16;
        }
     builder =  builder.reverse();
        return builder;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()){
            int n = sc.nextInt();
            sc.nextLine();
            int shiftNum = sc.nextInt();
            sc.nextLine();
            int outCome = 0;
            StringBuilder builder = new StringBuilder();
            switch (shiftNum){
                case 2: outCome = shiftTwo(n);
                    System.out.println(outCome);break;
                case 8: outCome = shiftEight(n);
                    System.out.println(outCome);break;
                case 16: builder = shiftSixTeen(n);
                    System.out.println(builder);break;
            }
        }

    }
}
